<?
include("/var/www/html/new/com.inc.php");
$ordid=$_REQUEST["ordid"];
$num=$_REQUEST["num"];
$ac3=$GLOBALS['_ac'];
$pw3=$GLOBALS['_pw'];
$s3 = new SoapClient(null,array("location" => "http://localhost/open/openService/s_insideMX.php","uri" => "www.16u.com?ac_16u=$ac3|pw_16u=$pw3|auth_16u=true"));
$xml=$s3->Order_Globle_Search(0,0,0,0,"","","","","","","","",$ordid,"",0,"","","",1,0,0,1);
if(is_numeric($xml)){
	echo "<script>alert('错误".$xml."');</script>";
	exit;
}
else{
	$arr=simplexml_load_string($xml);//var_dump($arr);
//	echo $arr->Rec[0]->UUfromt;
	$sel="select buy_limit_low as mix from uu_jq_ticket where pid=".$arr->Rec[0]->UUpid;
	if($arr->Rec[0]->UUlid==-1){
		$isL=true;
		$xml=$s3->Order_Route_Search("","","","","","","","","","",$ordid,"","","","","","","",0,1,0);
		if(!is_numeric($xml)){
			$arr=simplexml_load_string($xml);
		}
		elseif($xml!=105){
			exit("<script>alert('".$xml."')</script>");
		}
		$sel="select p_limit_low as mix from uu_route where pid=".$arr->Rec[0]->UUpid;
	}
	$GLOBALS['le']->query($sel);
	$GLOBALS['le']->fetch_assoc();
	if($GLOBALS['le']->f('mix')>$num){
		echo "<script>alert('修改数量低于产品购买所需的最低数量!');</script>";
		exit;
	}
	if((int)$arr->Rec[0]->UUtnum<$num){
		echo "<script>alert('修改数量不可高于原先预定的数量!');</script>";
		exit;
	}
    if((int)$arr->Rec[0]->UUlid==406) {
        include '/var/www/html/new/jq/com/func.inc.php';
        include '/var/www/html/pay/pay.func.php';
        $params = array(
            'ORDERID'=>(string)$arr->Rec[0]->UUordernum,
            'ORDERDATE'=>date("YmdHis"),
            'COUNT'=>$num,
            'PRICE'=>(float)$arr->Rec[0]->UUtprice,
            'AMOUNT'=>(float)$arr->Rec[0]->UUtprice*$num,
            'USER'=>'order',
            'PWD'=>'!@#123'
        );//var_dump($params);
        $logWord = date('Y-m-d H:i:s') . '|台儿庄订单修改[' . $orderId .']|返回结果:';
        $res_list = array(-2=>'已修改',-1=>'未查询到订单',0=>'失败',1=>'成功');
        try{
            $request_res = request_post('http://60.214.151.118:88/et/ebusiness/modifyOrder.do',$params);
            //$request_res = json_decode($request_res,true);
            $logWord .= $res_list[$request_res];
            writeLog($logWord, ZJ_LOG_PATH);
        } catch(Exception $e) {
            $logWord .= '失败|错误信息:' . $e->getMessage();
            writeLog($logWord, ZJ_LOG_PATH);
        }
    }
	$res = $s3->Order_Change_Pro($ordid,(int)$num,(float)$arr->Rec[0]->UUtprice*100*$num,0);
	if($res!=100){
		echo "<script>alert('错误".$res."')</script>";
		exit;
	}
	else{
		if(is_numeric((string)$arr->Rec[0]->UUfromt)){
			$sel="select online from uu_distributor where lvl=1 and oid=".(string)$arr->Rec[0]->UUfromt;
			$GLOBALS['le']->query($sel);
			$GLOBALS['le']->fetch_assoc();
			if($GLOBALS['le']->f('online')==0){
				$str="update uu_priceset set buy=buy+(".$num-(int)$arr->Rec[0]->UUtnum.") where pid=".$arr->Rec[0]->UUmid." and tid=".$arr->Rec[0]->UUpid;
				$GLOBALS['le']->query($str);
			}
		}
	}
	/* if(is_numeric((string)$arr->Rec[0]->UUfromt)){
		$sel="select online from uu_distributor where lvl='1' and oid = ".$arr->Rec[0]->UUfromt;
		$GLOBALS['le']->query($sel);
		$GLOBALS['le']->fetch_assoc();
		$online=$GLOBALS['le']->f("online");
		if($online=="1"){
			$res=$s3->Payed_Order_Change($ordid, $num);
			if($res!=100){
				echo "<script>alert('错误".$res."')</script>";
				exit;
			}
		}
		else{
			$res=$s3->Group_Order_Change($ordid, $num);
			if($res!=100){
				echo "<script>alert('错误".$res."')</script>";
				exit;
			}
		}
	}
	else{
		$res=$s3->Group_Order_Change($ordid, $num);
		if($res!=100){
				echo "<script>alert('错误".$res."')</script>";
				exit;
			}
	} */
	echo "<script>alert('修改成功!')</script>";
}
?>